In [9]:
# get ic decay
from get_data import get_data,bars
from singletrader.processors.cs_processor import CsWinzorize
from singletrader.shared.utility import save_pkl
from singletrader.factorlib import FactorEvaluation,summary_plot
import pandas as pd
import plotly.express as px
from plotly.figure_factory import create_table
import warnings
warnings.filterwarnings('ignore')
In [2]:
data = get_data().dropna() #获取处理好的数据
features = [_f for _f in data.columns if _f not in bars] + ['ep','circulating_market_cap']
bar_data = data[bars]
# bar_data.head()
In [3]:
liquidity_group = data.groupby(level=0).apply(lambda x:pd.qcut(x['amount3M'],3,labels=['low','medium','high'])).droplevel(0)
ep_group = data.groupby(level=0).apply(lambda x:pd.qcut(x['ep'],3,labels=['low','medium','high'])).droplevel(0)
high_liq =(liquidity_group=='high').astype(int)

Tips¶

- 为了确保因子作用方向一致,Long/Short方向选定使用的是全样本中的因子表现,与选定的start_date/end_date无关

summary of all factors¶

In [4]:
# 非行业中性化(全市场)
fe = FactorEvaluation(bar_data=data[bars],factor_data=data[features],freq=12,winzorize=True,standardize=True,industry_neutralize=False)
fe.get_summary(add_shift=0,start_date='2010-01-01',end_date='2022-12-31',base='close') # forward_return: 下月收盘-本月收盘
# fe.get_summary(add_shift=0,start_date='2010-01-01',end_date='2022-12-31',universe=high_liq,base='close-open') # forward_return: 下月收盘-下月开盘
start_date:2010-01-01 / end_date:2022-12-31
Out[4]:
skew adjskew distance mom6x3 mom9x3 mom12x3 mom1M mom2M mom3M mom6M turnover3M amount3M stddev_diff stddev ep circulating_market_cap
ic.mean -0.0220 -0.0251 0.0015 0.0014 0.0075 0.0093 -0.0409 -0.0495 -0.0438 -0.0324 -0.0417 -0.0416 -0.0079 -0.0375 0.0111 -0.0104
ic.t-stats -4.5870 -5.4944 0.1332 0.1753 0.8213 0.9784 -4.4306 -4.6343 -4.2191 -3.0323 -3.7078 -4.6622 -1.4904 -3.0344 1.6189 -1.2103
AnnRet_Long 0.0293 0.0349 0.0233 -0.0068 -0.0075 0.0056 0.0379 0.0663 0.0599 0.0479 0.0499 0.1133 -0.0266 0.0240 0.0001 0.1391
AnnRet_short -0.0571 -0.0543 0.0083 -0.0144 -0.0379 -0.0370 -0.1016 -0.1170 -0.1081 -0.0891 -0.0807 -0.1114 -0.0493 -0.0812 -0.0154 -0.0745
AnnRet 0.0865 0.0892 0.0150 0.0077 0.0304 0.0426 0.1395 0.1833 0.1680 0.1369 0.1306 0.2247 0.0227 0.1052 0.0155 0.2136
SR_Long 0.6867 0.8823 0.2783 -0.1097 -0.0965 0.0703 0.4799 0.8358 0.7678 0.5829 0.4982 1.3748 -0.6219 0.2300 0.0008 1.6172
SR_Short -1.3087 -1.3072 0.0908 -0.1901 -0.6241 -0.5720 -1.2536 -1.1988 -1.1653 -0.9704 -0.9295 -1.2533 -0.9876 -0.8907 -0.2853 -0.6975
SR 1.1350 1.2716 0.0891 0.0597 0.2322 0.3100 0.9670 1.0915 1.0446 0.8289 0.7313 1.4213 0.2896 0.5722 0.1299 1.1544
TO_Long 0.7752 0.7770 0.2492 0.5011 0.3180 0.2646 0.8119 0.6024 0.5018 0.3718 0.1533 0.1976 0.8950 0.4735 0.0852 0.0907
TO_Short 0.7848 0.7834 0.3552 0.4449 0.3710 0.3071 0.7738 0.5440 0.4431 0.3166 0.1875 0.1484 0.8961 0.5763 0.0728 0.0499
In [5]:
# 行业中性化(全市场)
fe = FactorEvaluation(bar_data=data[bars],factor_data=data[features],freq=12,winzorize=True,standardize=True,industry_neutralize=True)
fe.get_summary(add_shift=0,start_date='2010-01-01',end_date='2022-12-31',base='close')
start_date:2010-01-01 / end_date:2022-12-31
Out[5]:
skew_GN adjskew_GN distance_GN mom6x3_GN mom9x3_GN mom12x3_GN mom1M_GN mom2M_GN mom3M_GN mom6M_GN turnover3M_GN amount3M_GN stddev_diff_GN stddev_GN ep_GN circulating_market_cap_GN
ic.mean -0.0220 -0.0253 0.0087 -0.0008 0.0017 0.0014 -0.0489 -0.0543 -0.0494 -0.0381 -0.0435 -0.0419 -0.0095 -0.0393 0.0047 -0.0102
ic.t-stats -5.2690 -6.3374 0.8678 -0.1349 0.2458 0.1899 -6.2804 -6.0074 -5.5065 -4.2273 -4.6611 -5.4288 -2.1064 -3.5876 0.8465 -1.3894
AnnRet_Long 0.0283 0.0368 0.0387 0.0069 -0.0040 -0.0014 0.0729 0.0876 0.0835 0.0741 0.0659 0.0865 -0.0108 0.0429 0.0165 0.0424
AnnRet_short -0.0585 -0.0525 -0.0024 -0.0073 -0.0114 -0.0032 -0.1101 -0.1154 -0.1068 -0.0880 -0.0783 -0.1089 -0.0464 -0.0814 -0.0044 -0.0678
AnnRet 0.0868 0.0893 0.0412 0.0141 0.0074 0.0018 0.1829 0.2030 0.1903 0.1621 0.1442 0.1954 0.0356 0.1244 0.0208 0.1101
SR_Long 0.7582 1.0026 0.5360 0.1597 -0.0611 -0.0197 1.1731 1.3320 1.3063 1.1192 0.9075 1.5332 -0.3013 0.4775 0.2082 1.0895
SR_Short -1.5970 -1.4797 -0.0305 -0.1122 -0.2691 -0.0739 -1.5939 -1.3665 -1.2638 -1.0823 -1.0394 -1.3354 -1.0924 -1.0841 -0.0882 -0.7076
SR 1.3908 1.4400 0.2854 0.1516 0.0781 0.0183 1.6254 1.4648 1.3864 1.1897 1.0566 1.5968 0.5688 0.8023 0.2245 0.9276
TO_Long 0.7756 0.7768 0.2564 0.4964 0.3209 0.2683 0.8079 0.5956 0.4975 0.3675 0.1744 0.1780 0.8942 0.5059 0.1023 0.0673
TO_Short 0.7856 0.7834 0.3489 0.4473 0.3665 0.3029 0.7764 0.5450 0.4447 0.3202 0.1868 0.1550 0.8964 0.5848 0.0818 0.0496
In [6]:
# 行业中性化因子(高流动性股票池)
fe = FactorEvaluation(bar_data=data[bars],factor_data=data[features],freq=12,winzorize=True,standardize=True,industry_neutralize=True)
fe.get_summary(add_shift=0,start_date='2010-01-01',universe=high_liq,end_date='2022-12-31',base='close') # forward_return: 下月收盘-本月收盘
start_date:2010-01-01 / end_date:2022-12-31
Out[6]:
skew_GN adjskew_GN distance_GN mom6x3_GN mom9x3_GN mom12x3_GN mom1M_GN mom2M_GN mom3M_GN mom6M_GN turnover3M_GN amount3M_GN stddev_diff_GN stddev_GN ep_GN circulating_market_cap_GN
ic.mean -0.0202 -0.0138 -0.0039 0.0175 0.0216 0.0235 -0.0465 -0.0478 -0.0388 -0.0172 -0.0490 -0.0222 0.0032 -0.0304 0.0338 0.0152
ic.t-stats -4.1262 -2.8306 -0.3408 2.0443 2.2881 2.4099 -4.9462 -4.6531 -3.9111 -1.6463 -3.9959 -2.9157 0.5216 -2.5719 3.5621 1.3980
AnnRet_Long -0.0661 -0.0711 -0.0887 -0.0672 -0.0505 -0.0453 -0.0351 -0.0187 -0.0397 -0.0805 -0.0291 -0.0646 -0.1123 -0.0816 -0.0458 -0.0630
AnnRet_short -0.1340 -0.1176 -0.0911 -0.1258 -0.1518 -0.1439 -0.1899 -0.1878 -0.1732 -0.1363 -0.1898 -0.1410 -0.1247 -0.1641 -0.1668 -0.1102
AnnRet 0.0679 0.0465 0.0024 0.0586 0.1013 0.0986 0.1548 0.1692 0.1335 0.0557 0.1607 0.0764 0.0124 0.0826 0.1210 0.0472
SR_Long -1.0345 -1.0678 -0.7942 -0.5881 -0.4273 -0.3794 -0.4034 -0.1969 -0.4437 -0.9809 -0.2560 -1.0227 -1.1749 -0.9331 -0.3338 -0.3970
SR_Short -1.6535 -1.4739 -0.9318 -1.6347 -2.0101 -1.8337 -1.5793 -1.5382 -1.4480 -1.0857 -1.6915 -1.0870 -1.7720 -1.4174 -2.1798 -1.5303
SR 0.9311 0.6565 0.0147 0.4621 0.7559 0.7285 1.1158 1.1063 0.9472 0.3831 0.9220 0.7097 0.1319 0.5321 0.8275 0.2722
TO_Long 0.8134 0.8129 0.4559 0.4921 0.3779 0.3286 0.8371 0.6644 0.5486 0.4203 0.2118 0.4426 0.9244 0.5675 0.1787 0.0699
TO_Short 0.8138 0.8148 0.3572 0.5617 0.4574 0.4036 0.8083 0.6337 0.5260 0.3792 0.2880 0.1861 0.9117 0.6293 0.2429 0.2642

details of mom3M¶

收益曲线和表格指标,均是针对超额收益,benchmark用的是equal weighted

In [7]:
factor='mom3M_GN'
report = fe.get_factor_detail_report(factor=factor,add_shift=0,base='close',start_date='2010-01-01',end_date='2022-12-31',total=False,excess_return=True,holding_period=1)
summary_plot(report)
In [8]:
group_ic = fe.factor_ana(factor=factor,ep_group=ep_group,liquidity_group=liquidity_group,add_shift=0,base='close')
bar = px.bar(group_ic['ic.mean'].reset_index(),x='level_1',y='ic.mean',color='level_0',barmode='group',title='ic of different ep & lquidity')
bar.show()
In [ ]: